package cn.lyjuan.archetypes.bms.web.property;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;


@Component(SysProperties.SPRING_NAME)
@PropertySource("classpath:property/sys.properties")
public class SysProperties implements IShareProperties
{

    public static final String SPRING_NAME = "sysProperties";
    /**
     * 项目名称
     */

    private String name;

    /**
     * 首页内容的模版文件名称，
     * 使用 include 方式包含
     */

    private String indexUrl;

    /**
     * 请求后缀
     */

    private String urlSuffix = "";

    /**
     * 静态服务器直接访问地址，未开启CDN
     */

    private String styleUrl;

    /**
     * 静态服务器的CDN地址
     */

    private String styleCDNUrl;

    /**
     * 项目 copyright 信息
     */
    private String copyright;

    /**
     * 分页对象参数名称
     */
    private String pageName;

    /**
     * pageNum参数名
     */
    private String pageNumName;

    /**
     * pageSize参数名
     */
    private String pageSizeName;

    /**
     * totalCount参数名
     */
//    private String pageTotalCountName;

    /**
     * pageSize默认值
     */
    private Integer pageSizeDef;

    /* ****** 利用 Setting 方法注入 ******* */

    @Value("${sys.project.name}")
    public void setName(String name)
    {
        this.name = name;
    }

    @Value("${sys.project.index.url}")
    public void setIndexUrl(String indexUrl)
    {
        if (null == indexUrl || "".equals(indexUrl.trim()))
            return;

        this.indexUrl = indexUrl;
    }

    @Value("${sys.url.suffix}")
    public void setUrlSuffix(String urlSuffix)
    {
        if (null == urlSuffix || "".equals(urlSuffix.trim()))
            return;

        if (!urlSuffix.startsWith("."))
            urlSuffix = "." + urlSuffix;

        this.urlSuffix = urlSuffix;
    }

    @Value("${sys.url.style}")
    public void setStyleUrl(String styleUrl)
    {
        this.styleUrl = styleUrl;
    }

    @Value("${sys.url.style.cdn}")
    public void setStyleCDNUrl(String styleCDNUrl)
    {
        this.styleCDNUrl = styleCDNUrl;
    }

    @Value("${sys.copyright}")
    public void setCopyright(String copyright)
    {
        this.copyright = copyright;
    }


    @Value("${sys.page.number.name}")
    public void setPageNumName(String pageNumName)
    {
        this.pageNumName = pageNumName;
    }

    @Value("${sys.page.size.name}")
    public void setPageSizeName(String pageSizeName)
    {
        this.pageSizeName = pageSizeName;
    }

    @Value("${sys.page.size.default}")
    public void setPageSizeDef(Integer pageSizeDef)
    {
        this.pageSizeDef = pageSizeDef;
    }

/*    @Value("${sys.page.totalcount.name}")
    public void setPageTotalCountName(String pageTotalCountName)
    {
        this.pageTotalCountName = pageTotalCountName;
    }*/

    @Value("${sys.page.name}")
    public void setPageName(String pageName)
    {
        this.pageName = pageName;
    }

    public String getPageName()
    {
        return pageName;
    }

/*    public String getPageTotalCountName()
    {
        return pageTotalCountName;
    }*/

    public Integer getPageSizeDef()
    {
        return pageSizeDef;
    }

    public String getPageSizeName()
    {
        return pageSizeName;
    }
    public String getPageNumName()
    {
        return pageNumName;
    }
    public String getStyleUrl()
    {
        return styleUrl;
    }

    public String getIndexUrl()
    {
        return indexUrl;
    }

    public String getCopyright()
    {
        return copyright;
    }

    public String getUrlSuffix()
    {
        return urlSuffix;
    }


    public String getName()
    {
        return name;
    }


    public String getStyleCDNUrl()
    {
        return styleCDNUrl;
    }


    @Override
    public String toString()
    {
        return "SysProperties{" +
                "name='" + name + '\'' +
                ", indexUrl='" + indexUrl + '\'' +
                ", urlSuffix='" + urlSuffix + '\'' +
                ", styleUrl='" + styleUrl + '\'' +
                ", styleCDNUrl='" + styleCDNUrl + '\'' +
                ", copyright='" + copyright + '\'' +
                '}';
    }
}
